package com.fare.taluo.application.impl.system.register;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fare.taluo.application.system.register.RegistercodeApplication;
import com.fare.taluo.core.domain.system.RegistercodeEntity;
import com.fare.taluo.vo.registercode.RegisterCodeVO;



@Transactional
@Scope("singleton")
@Service("registercodeApplication")
public class RegistercodesImpl implements RegistercodeApplication{

	@Override
	public List<RegisterCodeVO> findRegistercodes(String code) {
		List<RegisterCodeVO> listVO = new ArrayList<RegisterCodeVO>();
		RegistercodeEntity repository =new RegistercodeEntity();
		List<RegistercodeEntity> list=new ArrayList<RegistercodeEntity>();
		list=repository.findRegistercodes(code);
		
		if(list !=null && list.size()>0){
			for(RegistercodeEntity entity:list){
				RegisterCodeVO vo=new RegisterCodeVO();
				vo.setId(entity.getId());
				vo.setCreateTime(entity.getCreateTime());
				vo.setHbaseKey(entity.getHbaseKey());
				vo.setName(entity.getName());
				vo.setRegisterCode(entity.getRegisterCode());
				vo.setURLS(entity.getURLS());
				vo.setEffectiveDate(entity.getEffectiveDate());
				vo.setCarrierKey(entity.getCarrierKey());
				listVO.add(vo);
			}
		}
		
		return listVO;
	}

	@Override
	public void saveURLS(RegisterCodeVO vo) {
		RegistercodeEntity entityVO=new RegistercodeEntity();
		entityVO.setCreateTime(vo.getCreateTime());
		entityVO.setHbaseKey(vo.getHbaseKey());
		entityVO.setName(vo.getName());
		entityVO.setRegisterCode(vo.getRegisterCode());
		entityVO.setURLS(vo.getURLS());
		entityVO.setId(vo.getId());
		entityVO.setEffectiveDate(vo.getEffectiveDate());
		entityVO.setCarrierKey(vo.getCarrierKey());
		entityVO.saveURLS(entityVO);
		
	}

	@Override
	public List<RegisterCodeVO> checkCode(String code, String habaseKey) {

		RegistercodeEntity entity=new RegistercodeEntity();
		List<RegistercodeEntity> list=entity.checkCode(code,habaseKey);
		List<RegisterCodeVO> volist=new ArrayList<RegisterCodeVO>();
		if(list !=null || list.size()>0){
			for(RegistercodeEntity task:list){
				RegisterCodeVO vo=new RegisterCodeVO();
				vo.setCreateTime(task.getCreateTime());
				vo.setHbaseKey(task.getHbaseKey());
				vo.setId(task.getId());
				vo.setName(task.getName());
				vo.setURLS(task.getURLS());
				vo.setRegisterCode(task.getRegisterCode());
				vo.setEffectiveDate(task.getEffectiveDate());
				vo.setCarrierKey(task.getCarrierKey());
				volist.add(vo);
			}
		}
		return volist;
	}

	@Override
	public RegisterCodeVO getCodeDateByCode(String registerCode) {
		
		RegisterCodeVO vo=new RegisterCodeVO();
		RegistercodeEntity ro=new RegistercodeEntity().getCodeDateByCode(registerCode);
		if(vo !=null){
			vo.setCreateTime(ro.getCreateTime());
			vo.setEffectiveDate(ro.getEffectiveDate());
			vo.setHbaseKey(ro.getHbaseKey());
			vo.setId(ro.getId());
			vo.setURLS(ro.getURLS());
			vo.setRegisterCode(ro.getRegisterCode());
			vo.setCarrierKey(ro.getCarrierKey());
			vo.setName(ro.getName());
		}
		return vo;
	}

	
	
	
	
	


}
